//
//  CLDisplayNodeLink.h
//  ComponentLinkDemo
//
//  Created by Jeanson on 2017/3/7.
//  Copyright © 2017年 zhenby. All rights reserved.
//

#pragma once
#import <objc/runtime.h>
#import "CLPViewComponent.h"
#import "CLLayoutSupportNode.h"
#import "NSObject+LayoutSupporterStore.h"
#import "CLLayoutSupportNode.h"
#import "_CLPLayoutSupporter.h"

NS_ASSUME_NONNULL_BEGIN

static inline id<_CLPLayoutSupporter> _Nullable CLLayoutElementToLayoutSupporter(id<CLPLayoutElement> _Nonnull layoutElement) {
    id<_CLPLayoutSupporter> supporter = [(NSObject*)layoutElement layoutSupporter];
    if (supporter) {
        return supporter;
    }
    return nil;
}

static inline id<_CLPLayoutSupporter> _Nonnull CLCreateLayoutSupporterWithLayoutElement(id<CLPLayoutElement> _Nullable layoutElement) {
    CLLayoutSupportNode *wrapperNode = [[CLLayoutSupportNode alloc] initWithLayoutElement:layoutElement];
    return wrapperNode;
}

static inline void CLUnlinkLayoutSuppoterWithLayoutElement(id<_CLPLayoutSupporter> _Nullable supporter,id<CLPLayoutElement> _Nonnull element) {
    [(NSObject*)element storeLayoutSupporter:nil];
}


static inline void CLLinkLayoutSuppoterWithLayoutElement(id<_CLPLayoutSupporter> _Nullable supporter,id<CLPLayoutElement> _Nonnull element) {
    [(NSObject*)element storeLayoutSupporter:supporter];
}

NS_ASSUME_NONNULL_END
